﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace HZ.Supervise.Web.Secondphase.ReportHospitalPurchase
{
    public partial class PrescriopionDetail :BasePage
    {
        HZ.Supervise.IBLL.IBLL_Purchase ibllPurchase = HZ.Supervise.BLLFactory.IBLL_Purchase();
        public string ProcureCatalogID = "";
        public string PHospitalID = "";
        public string PdoctorName = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            ProcureCatalogID = Request.QueryString["ProcureCatalogID"];
            PHospitalID = Request.QueryString["PHospitalID"];
            PdoctorName = Request.QueryString["PdoctorName"];
            if (!IsPostBack)
            {
                setBind();
            }
        }
        public string SetSex(object obj) 
        {
            if (!string.IsNullOrEmpty(obj.ToString()))
            {
                if (obj.ToString().Equals("True"))
                {
                    return "男";
                }
                else 
                {
                    return "女";
                }
            }
            else 
            {
                return "";
            }
        }
        public void setBind()
        {
            string where = "";
            where += "and ProcureCatalogID='" + ProcureCatalogID + "'";
            where += "and PHospitalID='" + PHospitalID + "'";
            where += "and PdoctorName='" + PdoctorName + "'";
            if (!string.IsNullOrEmpty(txtPrescriptionName.Text.Trim()))
            {
                where += "and  PrescriptionName like '%"+txtPrescriptionName.Text.Trim()+"%'";
            }
            if (!string.IsNullOrEmpty(txtPatientName.Text.Trim()))
            {
                where += "and  PatientName like '%" + txtPatientName.Text.Trim() + "%'";
            }
            where += "order by Pcount desc";
            int totalCount = 0;
            DataTable dt = ibllPurchase.GetPrescriptionNameByPdoctorName(where, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            gvwHospitalList.DataSource = dt;
            if (dt.Rows.Count > 0)
            {
                lblGoodsId.Text = dt.Rows[0]["ProcureCatalogID"].ToString();
                lblProductName.Text = dt.Rows[0]["ProductName"].ToString();
                lblCompanyName.Text = dt.Rows[0]["Pcompanyname_sc"].ToString();
                lblMedicineModel.Text = dt.Rows[0]["PmedicineModelname"].ToString();
                lblOutLook.Text = dt.Rows[0]["Poutlookc"].ToString();
                lblFactor.Text = dt.Rows[0]["Pfactor"].ToString();
                lblUnit.Text = dt.Rows[0]["Punit"].ToString();
                lblGoodsName.Text = dt.Rows[0]["PgoodsName"].ToString();
                lblHospitalName.Text = dt.Rows[0]["PHospitalName"].ToString();
                lblDoctoryName.Text = dt.Rows[0]["PdoctorName"].ToString();
            }
            else
            {
                lblGoodsId.Text = "暂无符合条件的数据";
                lblProductName.Text = "暂无符合条件的数据";
                lblCompanyName.Text = "暂无符合条件的数据";
                lblMedicineModel.Text = "暂无符合条件的数据";
                lblOutLook.Text = "暂无符合条件的数据";
                lblFactor.Text = "暂无符合条件的数据";
                lblUnit.Text = "暂无符合条件的数据";
                lblGoodsName.Text = "暂无符合条件的数据";
            }
            gvwHospitalList.DataBind();
            AspNetPager1.RecordCount = totalCount;
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            setBind();
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void HzButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("PrescriptionDoctor.aspx?ProcureCatalogID="+ProcureCatalogID+"&PHospitalID="+PHospitalID);
        }
    }
}
